package com.zhoushihao.class0821;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;

public class Main {
    public static void main(String[] args) {
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd");
        String date  = "2025/08/21";
        LocalDate localDate = LocalDate.parse(date, dtf);
//        System.out.println(localDate);
//        System.out.println(localDate.getDayOfWeek());
//        System.out.println(localDate.getDayOfMonth());
//        System.out.println(localDate.getMonthValue());
//        System.out.println(localDate.getYear());
//        System.out.println(localDate.getDayOfYear());
        LocalDate firstDay = localDate.with(TemporalAdjusters.firstDayOfMonth());
        System.out.println(firstDay.getDayOfWeek());
        LocalDate lastDay = localDate.with(TemporalAdjusters.lastDayOfMonth());
        //获取时间戳
        LocalDateTime localDateTime = lastDay.atStartOfDay();
        Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
        long timestamp = instant.toEpochMilli();
        System.out.println(timestamp);
        //时间戳转换日期
        Instant instant2 = Instant.ofEpochMilli(timestamp);
        LocalDateTime localDateTime2 = LocalDateTime.ofInstant(instant2, ZoneId.systemDefault());
        LocalDate ld = localDateTime2.toLocalDate();
        System.out.println(ld);
    }
}
